package com.myrent.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.text.DecimalFormatSymbols;
import java.util.Date;

/**
 * 普通用户
 */
@Data
@Validated
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
public class User {

    @TableId(type = IdType.AUTO)
    private Integer userId;
    /**
     * 登录用的是手机号
     */
    @NotNull
    @Pattern(regexp = "^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))" +
            "[0-9]{8}$", message = "手机号格式错误")
    private String phoneNum;


    @NotNull
    @Pattern(regexp = "^[\\w]{8,16}$", message = "密码不合法")
    private String password;
    /**
     * 可以用来设置为平台管理员
     */
    private String role;

    private String salt;
    /**
     * 性别男生true。数据库为1.女生相反
     */
    private Boolean sex;

    private String username;

    @Email
    private String email;

    private String realName;

    private Date registerTime;

    private BigDecimal money;

    private Integer credit;


    @Override
    public String toString() {
        String ret = null;
        ObjectMapper mapper = new ObjectMapper();
        try {
            ret = mapper.writeValueAsString(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

}
